#include <iostream>
#include <fstream>
#include "double_endedQueue.h"
using namespace std;
bool myEqual(char* str1, char* str2);
int main() {
	char instruction[20];
	char AddLeft[10] = "AddLeft";
	char AddRight[10] = "AddRight";
	char DeleteRight[20] = "DeleteRight";
	char DeleteLeft[20] = "DeleteLeft";
	char Left[5] = "Left";
	char Right[10] = "Right";
	char IsFull[10] = "IsFull";
	char IsEmpty[10] = "IsEmpty";
	char End[5] = "End";
	Queue<int> Q(5);
	int x;
	ifstream read;
	read.open("d://input.txt");
	while (read.getline(instruction, 20,' \n')) {
		if (myEqual(instruction, AddLeft)) {
			if (Q.isFull())
				cout << "FULL" << '\n';
			else {
				int i = 0;
				while (instruction[i] != ' ')i++;
				x = instruction[i + 1];
				Q.addLeft(x - 48);
				Q.output(cout);
			}
		}
		else if (myEqual(instruction, AddRight)) {
			if (Q.isFull())
				cout << "FULL" << '\n';
			else {
				int i = 0;
				while (instruction[i] != ' ')i++;
				x = instruction[i + 1];
				Q.addRight(x - 48);
				Q.output(cout);
			}
		}
		else if (myEqual(instruction, DeleteLeft)) {
			if (Q.isEmpty())
				cout << "EMPTY" << '\n';
			else {
				Q.deleteLeft(x);
				Q.output(cout);
			}
		}
		else if (myEqual(instruction, DeleteRight)) {
			if (Q.isEmpty())
				cout << "EMPTY" << '\n';
			else {
				Q.deleteRight(x);
				Q.output(cout);
			}
		}
		else if (myEqual(instruction, Left)) {
			if (Q.isEmpty())
				cout << "EMPTY" << '\n';
			else {
				Q.left(x);
				cout << x << '\n';
			}
		}
		else if (myEqual(instruction, Right)) {
			if (Q.isEmpty())
				cout << "EMPTY" << '\n';
			else {
				Q.right(x);
				cout << x << '\n';
			}
		}
		else if (myEqual(instruction, IsFull)) {
			if (Q.isFull())
				cout << "Yes" << '\n';
			else
				cout << "No" << '\n';
		}
		else if (myEqual(instruction, IsEmpty)) {
			if (Q.isEmpty())
				cout << "Yes" << '\n';
			else
				cout << "No" << '\n';
		}
		else if (myEqual(instruction, End)) {
			break;
		}
		else
			cout << "WRONG" << '\n';
	}
	read.close();
	return 0;
}
bool myEqual(char* str1, char* str2) {
	for (int i = 0; str2[i] != '\0'; i++) {
		if (str1[i] == str2[i])
			continue;
		else
			return false;
	}
	return true;

}